package service

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
	"videosrv/basic/golbal"
	"videosrv/handler/request"
	"videosrv/model"
	"videosrv/pkg"
)

func Login(c *gin.Context) {
	req := request.User{}
	err := c.ShouldBind(&req)
	if err != nil {
		return
	}
	var user model.User

	golbal.DB.Debug().Where("username=?", user.Username).Find(&user)

	handler, err := pkg.TokenHandler(strconv.Itoa(int(user.ID)))
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"data": handler,
	})

}
